import {
    addInfo,
    addInfoDelay,
    readCounts
} from "@/api/insideMessage/management";

const state = {
    isDot: false
}
const mutations = {
    SET_ISDOT: (state, data) => {
        state.isDot = data;
    }
}
const actions = {
    // 判断账号是否有未读消息
    isReadCounts({ commit, state }, params) {
        return new Promise((resolve, reject) => {
            readCounts(params).then((res) => {
                if (res.data == 0) {
                    commit("SET_ISDOT", false)
                    resolve(res)
                } else {
                    commit("SET_ISDOT", true)
                    resolve(res)
                }
            }).catch(error => {
                reject(error)
            })
        })
    },
    // 定时消息发送
    addInfoDelayMessage({ commit, state }, params) {
        return new Promise((resolve, reject) => {
            addInfoDelay(params).then((res) => {
                resolve(res)
            }).catch(error => {
                reject(error)
            })
        })
    },

    // 实时消息发送
    addInfoMessage({ commit, state }, params) {
        return new Promise((resolve, reject) => {
            addInfo(params).then((res) => {
                resolve(res)
            }).catch(error => {
                reject(error)
            })
        })
    },
    // 改变状态
    changeIsDot({ commit, state }) {
        commit("SET_ISDOT", false)
    },
}


export default {
    namespaced: true,
    state,
    mutations,
    actions
}
